<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
	    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
	    <meta name="misapplication-tap-highlight" content="no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
	    <title>注册</title> 
	    <link href="css/mui.min.css" rel="stylesheet"/>
	    <link rel="stylesheet" type="text/css" href="css/common.css"/>
	    <link rel="stylesheet" type="text/css" href="css/register.css"/>
	</head>
	<body>
		<section class="res">
			<div class="imgDiv">
				<img src="img/register/3.png"/>
			</div>
			<div id="register">
				<ul class="resList">
					<li><input type="text" name="phoneNum" placeholder="登录手机号"/></li>
					<li class="reg"><input type="text" name="regNum" placeholder="验证码"/><button id="getReg" class="rt mui-btn">获取验证码</button></li>
					<li><button id="registerBtn" class="mui-btn mui-btn-block">注册</button></li>
				</ul>
			</div>
			<img src="img/register/footer.png" class="footer" />
		</section>
	</body>
	<script src="js/jquery.min.js"></script>
	<script src="js/mui.min.js"></script>
	<script src='js/basic.js'></script>
	<script type="text/javascript">
		mui.init();
		/*window.screen.height - window.innerHeight
		var screenHeight;
	    if (window.innerHeight){
	        screenHeight = window.innerHeight;
	    } else if ((document.body) && (document.body.clientHeight)){
	        screenHeight = document.body.clientHeight;
	    }
	    $("html,body").height(screenHeight);*/
	    /*$("html").htght($(window).innerHeight());*/
	   
		/**
		 * 验证码有效期倒计时
		 */
		var urls = {
			register:"http://47.94.137.154:8080/app/user/register",
			getCode:"http://47.94.137.154:8080/app/user/getVcode"
		}
		var regPhone = /^1[3|4|5|8][0-9]\d{4,8}$/,
		    countdown=60;
		function settime() { 
			var t=setTimeout(function() { 
			settime(); 
			},1000);
			if (countdown == 0) { 
				$('#getReg').removeAttr("disabled");    
				$('#getReg').text("获取验证码"); 
				countdown = 60; 
				clearTimeout(t);
			} else { 
				$('#getReg').attr("disabled", true); 
				$('#getReg').text("重新发送(" + countdown + ")"); 
				countdown--; 
			} 
		} 
	 	/*获取验证码*/	   
	   $("#getReg").on("click",function(){
	   	 var phoneNum = $('input[name="phoneNum"]').val();
	   		if(phoneNum==null||phoneNum==""){
	   			mui.toast("手机号码不能为空");
	   			return;
	   		}else if(!(regPhone.test(phoneNum))){
	   			mui.toast("手机号码格式不正确");
	   			return;
	   		}
	   		$.get(urls.getCode,{tel:phoneNum,type:"register"},function(res){
	   			if(res.code==1){
	   				mui.toast(res.msg);
	   			}else{
	   				settime();
	   			}
	   		},"json");
	   });
		/*注册验证手机号和验证码*/
		var url = window.location.href,
		   rid = GetQueryString('rid');
		$("#registerBtn").on("click",function(){
	  	 var phoneNum =  $('input[name="phoneNum"]').val(),
	         regNum =  $('input[name="regNum"]').val();
			if (countdown == 0) {
				mui.toast("获取验证码失败");
				$("#registerBtn").removeAttr("disabled");
				return;
			}
			
			if(phoneNum==null||phoneNum==""){
	   			mui.toast("手机号码不能为空");
	   			return;
	   		}else if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phoneNum))){
	   			mui.toast("手机号码格式不正确");
	   			return;
	   		}
	   		
	   		if(regNum==null||regNum==""){
	   			mui.toast("短信验证码不能为空");
	   			return;
	   		}
	   		$("#registerBtn").attr("disabled","disabled");
	   		console.log({tel:phoneNum,vcode:regNum,rid:GetQueryString('rid')})
	   		$.get(urls.register,{tel:phoneNum,vcode:regNum,rid:GetQueryString('rid')},function(res){
	   			console.log(res)
	   			if(res.code==0){
	   					
	   					//window.location.href="downApp.html";
	   			}else if(res.msg=="该用户已存在"){
	   					mui.toast(res.msg);
	   					//window.location.href="downApp.html";
	   			}else{
	   					mui.toast(res.msg);
	   			}
	   		},"json");
	  });
	</script>
</html>
